package com.greathf.hf_ywgl.aop;

import com.greathf.hf_ywgl.pojo.HF_Result;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class DataAspect {

    public static final Logger LOGGER = LoggerFactory.getLogger("aopLogger");


    @Pointcut("execution(* com.greathf.hf_ywgl.controller.WxsController.*(..))")
    private void pt(){}

    @Around("pt()")
    public Object recordDataSendBefore(ProceedingJoinPoint joinPoint) throws Throwable {
        // 记录方法执行的开始时间
        long begin = System.currentTimeMillis();

        // 得到返回结果
        Object result = joinPoint.proceed();
        if(null != result)
        {
            //joinPoint.
            HF_Result hf_result = (HF_Result)result;

            // 返回结果成功
            if (hf_result.fhjg.equals("1")) {
                LOGGER.info("开始记录");
            }
            else{ // 记录日志
                LOGGER.info("返回结果失败！");
            }
        }

        // 记录方法执行的结束时间
        long end = System.currentTimeMillis();

        log.info(joinPoint.getSignature() + "方法执行耗时: {}ms", end - begin);

        log.info("返回结果:", result.toString());



        LOGGER.info("开始记录123");

        return result;
    }
}
